<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="utf-8">
  <link href="{{url_for('static', filename='css/bootstrap.min.css')}}" rel="stylesheet">
  <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
  <title>车票购买系统</title>
  <style>
    .my-h1 {
        margin-bottom: 1rem!important;
		margin-top: 2rem!important;
        text-align: center;
        width: 100%;
        font-size: 52px;
    }
    .table-primary th {
        font-size: 30px;
    }
  </style>
</head>
<body class="bg-light">
    <div class="container">
        <h1 class="my-h1 text-center mt-4">车票购买</h1>
        <div class="row justify-content-center">
            <div class="col-md-6">
                <div class="card rounded bg-warning">
                    <div class="card-body">
                        <form action="/search" method="post" onsubmit="return validateForm()">
                            <div class="row mb-3">
                                <div class="col">
                                    <label for="start" class="form-label fs-5">出发地：</label>
                                </div>
                                <div class="col">
                                    <select id="start" name="start" class="form-select">
                                        {% for start_city in start_citys %}
                                            <option value="{{ start_city }}">{{ start_city }}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                            </div>
                            <div class="row mb-3">
                                <div class="col">
                                    <label for="end" class="form-label fs-5">目的地：</label>
                                </div>
                                <div class="col">
                                    <select id="end" name="end" class="form-select">
                                        {% for end_city in end_citys %}
                                            <option value="{{ end_city }}">{{ end_city }}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                            </div>
                            <div class="row mb-3">
                                <div class="col">
                                    <label for="date" class="form-label fs-5">日期：</label>
                                </div>
                                <div class="col">
                                    <input type="date" id="date" name="date" class="form-control">
                                </div>
                            </div>
                            <div class="row justify-content-center">
                                <div class="col-auto">
                                    <button type="submit" class="btn btn-primary">查询车票</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        function validateForm() {
            var start = document.getElementById("start").value;
            var end = document.getElementById("end").value;
            var date = document.getElementById("date").value;

            if (date === "") {
                alert("请选择日期");
                return false;
            }
            if (start === end) {
                alert("出发地和目的地不能相同");
                return false;
            }
            var today = new Date().toISOString().split("T")[0];
            if (date < today) {
                alert("无法选择比今天早的日期");
                return false;
            }
        }
    </script>
</body>
</html>
